package com.qfedu.controller;

import com.qfedu.pojo.req.PermissionReq;
import com.qfedu.pojo.resp.BaseResp;
import com.qfedu.service.PermissionService;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("permission")
@Api(tags = "权限管理")
public class PermissionController {

    @Autowired
    PermissionService permissionService;

    @RequiresPermissions("SelectPermission")
    @GetMapping("findAllPermission")
    public BaseResp findAllPermission(@RequestParam("page")Integer page,@RequestParam("size")Integer size) {
        return permissionService.findAllPermission(page, size);
    }

    @RequiresPermissions("UpdatePermission")
    @PostMapping("addPermission")
    public BaseResp addPermission(@RequestBody PermissionReq permissionReq) {
        return permissionService.addOrUpdPermission(permissionReq);
    }

    @RequiresPermissions("UpdatePermission")
    @PostMapping("updPermission")
    public BaseResp updPermission(@RequestBody PermissionReq permissionReq) {
        return permissionService.addOrUpdPermission(permissionReq);
    }

    @RequiresPermissions("UpdatePermission")
    @PostMapping("delPermission")
    public BaseResp delPermission(@RequestBody PermissionReq permissionReq) {
        return permissionService.delPermission(permissionReq);
    }
}
